package com.evil.application.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.evil.application.pojo.entity.ApplicationButton;
import com.evil.common.application.dto.button.ButtonSourceDTO;
import com.evil.common.core.enums.RCodeEnum;
import com.evil.common.core.exception.BusinessException;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

/**
 * 自定义按钮表
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
public interface ApplicationButtonMapper extends BaseMapper<ApplicationButton> {

    Optional<ApplicationButton> isExistById(Long id);

    default ApplicationButton findById(Long id) {
        return this.isExistById(id).orElseThrow(() -> new BusinessException(RCodeEnum.APPLICATION_BUTTON_NOT_EXIST, id));
    }

    Optional<ApplicationButton> isExistByKeyAndVersion(@Param("key") String key, @Param("version") Integer version);

    default ApplicationButton findByKeyAndVersion(String key, Integer version) {
        return this.isExistByKeyAndVersion(key, version).orElseThrow(() -> new BusinessException(RCodeEnum.APPLICATION_BUTTON_NOT_EXIST, (Object) key));
    }

    List<ApplicationButton> findByKey(String key);

    List<ApplicationButton> findByIds(@Param("ids") Collection<Long> ids);

    List<ApplicationButton> findByKeys(@Param("keys") Collection<String> keys, @Param("version") Integer version);

    List<ApplicationButton> findBySource(@Param("source") ButtonSourceDTO source);

    List<ApplicationButton> findBySources(@Param("sources") Collection<ButtonSourceDTO> sources);

    List<ApplicationButton> findByEnterpriseId(Long enterpriseId);
}